Group Importances#
In this notebook we show how to compute and interpret Overall Importances shown in InterpretML’s Global Explanations for EBMs. We also show how to compute importances of a group of features or terms.
Throughout the notebook we use term to denote both single features and interactions (pairs).
This notebook can be found in our examples folder on GitHub.
# install interpret if not already installed
try:
import interpret
except ModuleNotFoundError:
!pip install --quiet interpret pandas scikit-learn
Train an Explainable Boosting Machine (EBM) for a regression task
Let’s use the Boston dataset as a reference and train an EBM.
import numpy as np
import pandas as pd
from sklearn.datasets import load_diabetes
from interpret.glassbox import ExplainableBoostingRegressor
from interpret import set_visualize_provider
from interpret.provider import InlineProvider
set_visualize_provider(InlineProvider())
X, y = load_diabetes(return_X_y=True, as_frame=True)
ebm = ExplainableBoostingRegressor()
ebm.fit(X, y)
ExplainableBoostingRegressor()In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
ExplainableBoostingRegressor()
Explain the Model
EBMs provide two different kinds of explanations: global explanations about the overall model behavior and local explanations about individual predictions from the model.
Global Explanation
Global Explanations are useful for understanding what a model finds important, as well as identifying potential flaws in its decision making or the training data. Let’s start by computing and displaying a global explanation:
from interpret import show
show(ebm.explain_global(name='EBM'))
The overall importance for each term is calculated as the average absolute contribution (score) a term (feature or pair) makes when predicting across the training dataset. This way of measuring term importance tends to favor terms which, on average, have large impact on predictions for many cases. The overall importance is not a measure of positive/negative – it is a measure of how important each term is in the scores. For regression, these scores are represented in the same units as the y-axis of the feature graphs. For classification, the scores would be in logits.
Going beyond overall term importances, because EBMs are additive models we can measure exactly how each term contributes to a prediction. Let’s take a look at the graph of the term, bp, by selecting it in the drop-down menu.

The way to interpret this is that if a new datapoint came in with bp = 0.1, the model adds about +33.1 to the final prediction. However, for a different datapoint with bp = 0.13, the model would now add approx. +36.7 to the prediction.
To make individual predictions, the model uses each term graph as a look up table, notes the contribution per term, and sums them together with the learned intercept to make a prediction. In regression, the intercept is the mean target (label) of the training set, and each term adds or subtracts to this mean. In classification, the intercept reflects the base rate of the positive class on a log scale. The gray above and below the graph shows the confidence of the model in that region of the graph.
Local Explanations
We can see the full breakdown of a prediction on a single sample with Local Explanations. Here’s how to compute the prediction breakdown for the first sample in our dataset:
from interpret import show
show(ebm.explain_local(X[:1], y[:1]), 0)
Let’s take a look at the prediction by selecting it in the drop-down menu.

The model prediction is 188.50. We can see that the intercept adds about +151.9, bp subtracts about 0.02, and age adds about 0.04. If we repeat this process for all the terms, we’ll arrive exactly at the model prediction of 188.50.
Viewing _all_ term importances
Due to space limitations in our graphs, the term importance summary only shows the top 15 terms. To view the overall importances of all terms of a trained EBM - the scores shown in the global explanation summary - we use term_importances():
importances = ebm.term_importances()
names = ebm.term_names_
for (term_name, importance) in zip(names, importances):
print(f"Term {term_name} importance: {importance}")
Term age importance: 3.537486982281528
Term sex importance: 7.79639339089525
Term bmi importance: 16.989295350608018
Term bp importance: 10.39781942180925
Term s1 importance: 0.8755990800924706
Term s2 importance: 2.981734237198304
Term s3 importance: 7.0345279107407475
Term s4 importance: 6.530839119569931
Term s5 importance: 16.126063544925145
Term s6 importance: 5.424857988128763
Term age & s5 importance: 1.301029169064789
Term bmi & bp importance: 1.0154175308970659
Term bmi & s2 importance: 1.0049458565504945
Term bmi & s4 importance: 1.2408692405164738
Term bmi & s5 importance: 0.9295103524759374
Term bmi & s6 importance: 0.9690591129666642
Term bp & s1 importance: 0.7700657746326304
Term s1 & s5 importance: 1.3520828717481495
Term s5 & s6 importance: 1.9706009052451583
Note that mean absolute contribution isn’t the only way of calculating term importances. Another metric our package provides is the min_max option, which computes the difference between the max (the highest score on the graph) and min (the lowest score on the graph) values for each term. Term importance measured with min_max is a measure of the maximum impact a term can have, even though it might have this amount of impact on very few cases, whereas avg_weight(the default parameter) is a measure of typical (average) contribution of a term across all cases.
importances = ebm.term_importances("min_max")
names = ebm.term_names_
for (term, importance) in zip(names, importances):
print(f"Term {term} importance: {importance}")
Term age importance: 15.721025375974522
Term sex importance: 15.655613099176271
Term bmi importance: 94.03037200872657
Term bp importance: 66.57479230158046
Term s1 importance: 8.44262609614486
Term s2 importance: 22.67800490637469
Term s3 importance: 51.12489104713143
Term s4 importance: 30.757352250398053
Term s5 importance: 59.11522267878097
Term s6 importance: 38.94482406432282
Term age & s5 importance: 7.493417867895
Term bmi & bp importance: 11.643691773534334
Term bmi & s2 importance: 11.261509285546154
Term bmi & s4 importance: 6.501212305195825
Term bmi & s5 importance: 6.91174071555246
Term bmi & s6 importance: 8.027464177758857
Term bp & s1 importance: 9.038777333411272
Term s1 & s5 importance: 13.503355766819755
Term s5 & s6 importance: 18.71401122840917
Feature/Term Group Importances
We provide utility functions to compute the importances of groups of features or terms and, optionally, append these importances to the global feature attribution bar graph. Note that shape function graphs are not generated for groups of features/terms, just their overall importance is shown on the Summary.
Grouping terms and then calculating and displaying their importance does not change the model and the predictions it makes in any way – group importances are just a method for computing the importance of groups of terms in addition to the importances of individual terms that are already calculated. As you’ll see in the examples below, it’s OK for features/terms to overlap in different groups.
Computing group importances
Let’s use the Adult dataset and train an EBM for a classification task.
import numpy as np
import pandas as pd
from interpret.glassbox import ExplainableBoostingClassifier
df = pd.read_csv(
"https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data",
header=None)
df.columns = [
"Age", "WorkClass", "fnlwgt", "Education", "EducationNum",
"MaritalStatus", "Occupation", "Relationship", "Race", "Gender",
"CapitalGain", "CapitalLoss", "HoursPerWeek", "NativeCountry", "Income"
]
X = df.iloc[:, :-1]
y = df.iloc[:, -1]
adult_ebm = ExplainableBoostingClassifier()
adult_ebm.fit(X, y)
ExplainableBoostingClassifier()In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
ExplainableBoostingClassifier()
We then create a list of terms – single features or interactions – as our group and compute its importance:
from interpret.glassbox._ebm._research import *
social_feature_group = ["MaritalStatus", "Relationship", "Race", "Gender", "NativeCountry"]
importance = compute_group_importance(social_feature_group, adult_ebm, X)
print(f"Group: {social_feature_group} - Importance: {importance}")
Group: ['MaritalStatus', 'Relationship', 'Race', 'Gender', 'NativeCountry'] - Importance: 1.288248901881929
In this example we create a group with five terms and compute its importance. Similar to single feature importances, we interpret this score as the average absolute contribution this group of terms makes when predicting across the training dataset. Note that for each prediction, the contribution of each term in the group will be added before taking the absolute value.
We also have the option to create a global explanation containing the group importance or append it to an existing explanation:
my_global_exp = append_group_importance(social_feature_group, adult_ebm, X)
show(my_global_exp)
The importance of social_feature_group is about 1.30, which is higher than the importance of any individual feature/term:

We could make this type of comparison between different groups too:
education_feature_group = ["Education", "EducationNum"]
relationship_feature_group = ["MaritalStatus", "Relationship"]
social_feature_group = ["MaritalStatus", "Relationship", "Race", "Gender", "NativeCountry"]
my_global_exp = append_group_importance(social_feature_group, adult_ebm, X)
my_global_exp = append_group_importance(education_feature_group, adult_ebm, X, global_exp=my_global_exp)
my_global_exp = append_group_importance(relationship_feature_group, adult_ebm, X, global_exp=my_global_exp)
show(my_global_exp)
The importance of education_feature_group is about 0.52, higher than each of its individual terms but smaller than some individual terms such as Age. Remember, creating groups of features/terms does not, in any way, change the model and its predictions, it only allows you to estimate the importance of these groups.
This graph, for example, suggests that features related to relationships are more important than features reated to education.

We can also compare a group we are interested in (e.g. social_feature_group) with a group of all other reamining terms.
social_feature_group = ["MaritalStatus", "Relationship", "Race", "Gender", "NativeCountry"]
all_other_terms = [term for term in adult_ebm.term_names_ if term not in social_feature_group]
my_global_exp = append_group_importance(social_feature_group, adult_ebm, X)
my_global_exp = append_group_importance(all_other_terms, adult_ebm, X, group_name="all_other_terms", global_exp=my_global_exp)
show(my_global_exp)
Note that all_other_terms has the highest importance score, followed by social_feature_group.

It’s even possible to create a group with all terms.
all_terms_group = [term for term in adult_ebm.term_names_]
mew_global_exp = append_group_importance(all_terms_group, adult_ebm, X, group_name="all_terms")
show(mew_global_exp)
Finally, we also expose a function to compute the importances of a group of terms as well as all the model’s original terms.
my_dict = get_group_and_individual_importances([social_feature_group, education_feature_group], adult_ebm, X)
for key in my_dict:
print(f"Term: {key} - Importance: {my_dict[key]}")
Term: MaritalStatus, Relationship, Race, Gender, NativeCountry - Importance: 1.288248901881929
Term: Age - Importance: 0.8160224712710744
Term: CapitalGain - Importance: 0.6700317598906999
Term: Relationship - Importance: 0.6084610513303613
Term: MaritalStatus - Importance: 0.5386604382256514
Term: Education, EducationNum - Importance: 0.522761529058496
Term: EducationNum - Importance: 0.4031866690208291
Term: Occupation - Importance: 0.37117620650688893
Term: Gender - Importance: 0.3029448815756496
Term: HoursPerWeek - Importance: 0.29352194010467225
Term: CapitalLoss - Importance: 0.16890888593307907
Term: Education - Importance: 0.15831633428115274
Term: fnlwgt - Importance: 0.11481767671706336
Term: WorkClass - Importance: 0.08946841149611501
Term: Race - Importance: 0.06560751110415289
Term: Age & HoursPerWeek - Importance: 0.06396849273374584
Term: NativeCountry - Importance: 0.06160754930166207
Term: MaritalStatus & HoursPerWeek - Importance: 0.049871895673155975
Term: Relationship & HoursPerWeek - Importance: 0.04370721825611292
Term: Age & EducationNum - Importance: 0.03753665303299141
Term: EducationNum & MaritalStatus - Importance: 0.037074173835015385
Term: fnlwgt & Education - Importance: 0.03246044552311357
Term: Age & fnlwgt - Importance: 0.031834747827094834
Term: Gender & HoursPerWeek - Importance: 0.02654351447991803
Term: Age & Race - Importance: 0.025709264125685208
Term: Age & Relationship - Importance: 0.02140274373284773
Term: MaritalStatus & Gender - Importance: 0.01991653644620038
Term: WorkClass & Relationship - Importance: 0.01817804915218167
Term: WorkClass & Race - Importance: 0.007839613663537979